package ar.uade.fain.ai.tpo.view.seccion;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import ar.uade.fain.ai.tpo.Sistema;
import ar.uade.fain.ai.tpo.dto.SeccionDTO;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class AltaSeccion extends javax.swing.JFrame {

	private static final long serialVersionUID = 1L;

	private JButton altaSeccion;
	private JTextField nombreSeccion;
	private JTextField idGeneradoText;
	private JLabel idGeneradoLabel;
	private JLabel labelNombre;

	/**
	 * Auto-generated main method to display this JFrame
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AltaSeccion inst = new AltaSeccion();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}

	public AltaSeccion() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			getContentPane().setLayout(null);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				altaSeccion = new JButton();
				getContentPane().add(altaSeccion);
				altaSeccion.setText("Alta Seccion");
				altaSeccion.setBounds(39, 69, 109, 24);
				altaSeccion.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent evt) {
						if (!nombreSeccion.getText().isEmpty()) {
							SeccionDTO seccionDTO = new SeccionDTO();
							seccionDTO.setNombre(nombreSeccion.getText());
							Long idGenerado = Sistema.get().getSeccionControlador()
									.crearNuevaSeccion(seccionDTO);
							idGeneradoText.setText(idGenerado.toString());
						}
					}
				});
			}
			{
				nombreSeccion = new JTextField();
				getContentPane().add(nombreSeccion);
				nombreSeccion.setBounds(180, 22, 261, 23);
			}
			{
				labelNombre = new JLabel();
				getContentPane().add(labelNombre);
				labelNombre.setText("Nombre de la seccion");
				labelNombre.setBounds(27, 24, 153, 16);
			}
			{
				idGeneradoLabel = new JLabel();
				getContentPane().add(idGeneradoLabel);
				idGeneradoLabel.setText("ID generado:");
				idGeneradoLabel.setBounds(180, 73, 116, 15);
			}
			{
				idGeneradoText = new JTextField();
				getContentPane().add(idGeneradoText);
				idGeneradoText.setBounds(314, 70, 127, 22);
				idGeneradoText.setEditable(false);
				idGeneradoText.setForeground(Color.LIGHT_GRAY);
			}
			pack();
			this.setSize(463, 143);
		} catch (Exception e) {
			// add your error handling code here
			e.printStackTrace();
		}
	}

}
